package goods

import (
	"myserver/app/service/goods_service"
	"myserver/app/types"
	pkgApp "myserver/pkg/app"
	"myserver/pkg/constant"
	"net/http"

	"github.com/gin-gonic/gin"
)

type GoodsController struct{}

func (this GoodsController) AddGoods(c *gin.Context) {
	var (
		m   types.SysGoods
		app = pkgApp.Gin{C: c}
	)
	httpCode, errCode, err := pkgApp.BindAndValid(c, &m)
	if err != nil {
		app.Response(httpCode, errCode, err.Error())
		return
	}
	g := goods_service.GoodsService{Barcode: m.Barcode}
	err = g.AddGoods()
	if err != nil {
		app.Response(http.StatusInternalServerError, constant.ERROR, err.Error())
		return
	}
	app.Response(http.StatusOK, constant.SUCCESS, "添加成功")

}
